window.HTMLElement.prototype.scrollIntoView = function() {};
let friends_vm = new Vue({
    el:"#friends",
    data:{
        friends:[],
        id2:0,
    },
    created:function () {
        console.log("执行了方法");
        this.loadFriends();

    },
    methods:{
        loadFriends:function () {
            console.log("执行了加载好友！")
            axios({
                url:"/v1/friends/my",
                method:"GET"
            }).then(function (r){
                console.log("成功加载好友！")
                console.log(r)
                if(r.status==OK){
                    friends_vm.friends=r.data
                }
            })
        },
        changeFont:function (e){
            $(".wp-aside-nav__sub-item-body:eq("+(this.id2)+")").removeClass("wp-aside-nav__sub-item-body_click");
            if(e.target.className=="friend_list"){
                this.id2 = $(e.target).index();
            }else{
                this.id2 = $(e.target).parents(".friend_list").index();
            }
            $(".wp-aside-nav__sub-item-body:eq("+(this.id2)+")").addClass("wp-aside-nav__sub-item-body_click")
            chat_vm.chatHistory=(this.friends[this.id2]).chats
            console.log(chat_vm.chatHistory)
            var div = document.getElementsByClassName('content-main')

        }
    }
})

let chat_vm = new Vue({
    el:".content-chat-main",
    data:{
        chatHistory:[]
    },

})

let send_vm = new Vue({
    el:"#sendChat",
    data:{

    },
    methods:{
        saveChatHistory:function (){
            console.log("正在发送消息！")
            let chat = $(".send_text").text()
            let roomId = chat_vm.chatHistory[0].roomId
            let userId = friends_vm.friends[0].userId
            let masterId = chat_vm.chatHistory[0].masterId
            console.log(chat)
            let form = new FormData()
            form.append("chat",chat)
            form.append("roomId",roomId)
            form.append("userId",userId)
            form.append("masterId",masterId)
            console.log(form)
            axios({
                url:"/v1/chats",
                method:"post",
                data:form
            }).then(function (r){
                console.log(r.data)
                if(r.data=="OK"){
                    $(".send_text").text("")
                    console.log("发送成功！")
                }else{
                    console.log(r.data)
                }
            })
        }
    }
})